<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}style/login.css?v={{ layui.admin.v }}-1" media="all">
</script>

<style>
    .layui-btn {
        background-color: #06B991 100%;
    }
    
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    
    html {
        width: 100%;
        height: 100%;
        font-size: 16px;
    }
    
    body {
        width: 100%;
        height: 100%;
        -moz-user-select: none;
        /*火狐*/
        /*禁止用户在页面选择文字*/
        -webkit-user-select: none;
        /*webkit浏览器*/
        -ms-user-select: none;
        /*IE10*/
        -khtml-user-select: none;
        /*早期浏览器*/
        user-select: none;
    }
    
    .code {
        padding-top: 50px;
        width: 400px;
        margin: 0 auto;
    }
    
    .input-val {
        width: 295px;
        background: #ffffff;
        height: 2.8rem;
        padding: 0 2%;
        border-radius: 5px;
        border: none;
        border: 1px solid rgba(0, 0, 0, .2);
        font-size: 1.0625rem;
    }
    
    #canvas {
        display: inline-block;
        border: 1px solid #ccc;
        border-radius: 5px;
        cursor: pointer;
    }
    
    .btn {
        width: 100px;
        height: 40px;
        background: #f1f1f1;
        border: 1px solid #ccc;
        border-radius: 5px;
        margin: 20px auto 0;
        display: block;
        font-size: 1.2rem;
        color: #e22e1c;
        cursor: pointer;
    }
    
    .bb {
        height: 20px;
        line-height: 20px;
        background-color: transparent;
        color: black;
        margin: 0 0 15px 5px;
    }
    
    sup {
        color: red;
    }
</style>
<link rel="stylesheet" href="/start/layui/css/login.css">
<div class="hd">
    <div class="hdxinxi">
        <div class="logo">
            <img src="/start/layui/images/logo.png" alt="">
        </div>
        <div class="name">XXXAGV管理平台</div>
    </div>
</div>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;height: 60vh;">
    <div class="logo">LOGO</div>
    <div class="layadmin-user-login-main box">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h1 class="denglu">用户登录</h1>
            <!-- <p>工软后台管理系统</p> -->
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">

            <div class="layui-form-item">
                账号：
                <!-- <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label> -->
                <input type="text" name="userName" id="LAY-user-login-username" lay-verify="required" class="put">
            </div>
            <div class="layui-form-item">
                密码：
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" class="put">
            </div>
            <!-- <div class="layui-form-item">
                验证码：
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" class="putmin">
            </div> -->
            <!-- <div class="layui-form-item" style="margin-bottom: 20px;">
                <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
                <a lay-href="/user/forget" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码？</a>
            </div> -->
            <!-- <div class="code">
                <input type="text" value="" placeholder="请输入验证码（不区分大小写）" class="input-val" />
                <canvas id="canvas" width="100" height="43"></canvas>
                <button class="btn">提交</button>
            </div> -->
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 录</button>
            </div>

        </div>
        <!-- <button class="layui-btn bb" lay-submit lay-filter="LAY-user-back-open">注册</button> -->
    </div>
</div>
<!-- <div class="banquan">版权所有©南京颜忆录文化传媒</div> -->
<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
<script src="/start/layui/code.js"></script>
<script src="/start/layui/md5.js"></script>
<script>
    layui.use(['admin', 'form', 'user'], function() {
        var $ = layui.$,
            setter = layui.setter,
            admin = layui.admin,
            form = layui.form,
            router = layui.router(),
            search = router.search;

        form.render();
        //注册用户
        // form.on('submit(LAY-user-back-open)', function() {
        //     console.log('注册新用户')
        //     layer.open({
        //         type: 1,
        //         area: ['500px', '545px'],
        //         title: '用户注册',
        //         content: '<div class="layadmin-user-login-box layadmin-user-login-header"><h1 class="denglu">注册登录</h1></div><div class="layadmin-user-login-box layadmin-user-login-body layui-form"><div class="layui-form-item">账号<sup>*</sup>：<input type="text" name="userName" id="regname" lay-verify="required" class="put"></div><div class="layui-form-item">密码<sup>*</sup>：<input type="password" name="password" id="regpass" lay-verify="required" class="put"></div><div class="layui-form-item">公司id<sup>*</sup>:<input type="text" id="regctrlid" name="companyId" lay-verify="required" class="put"></div><div class="layui-form-item">avgid<sup>*</sup>:<input type="text" name="agvId" lay-verify="required" id="regagvid" class="put"></div><div class="layui-form-item">ctrlId<sup>*</sup>:<input type="text" id="companyid" name="ctrlId" lay-verify="required" class="put"></div><div class="layui-form-item"><button class="layui-btn layui-btn-fluid" lay-submit id="register" lay-filter="LAY-user-login-register">立即注册</button></div></div>', //这里content是一个普通的String
        //         success: function() {
        //             $('#register').click(function() {
        //                 console.log('shabi11111')
        //                     //注册用户接口
        //                 admin.req({
        //                     url: setter.request.baseUrl + 'user/add',
        //                     data: JSON.stringify({
        //                         "userName": $('#regname').val(),
        //                         'password': $('#regpass').val(),
        //                         'ctrlId': $('#regctrlid').val(),
        //                         'companyId': $('#companyid').val(),
        //                         'agvId': $('#regagvid').val()
        //                     }),
        //                     type: "post",
        //                     dataType: "json",
        //                     contentType: "application/json",
        //                     done: function(res) {
        //                         console.log(res)


        //                         layer.closeAll();
        //                         if (res.msg == '操作成功') {
        //                             layer.msg('注册成功~')
        //                         }
        //                     }
        //                 });
        //             })

        //         }
        //     });
        // })


        //提交
        form.on('submit(LAY-user-login-submit)', function(obj) {
            // console.log(obj.field)
            //请求登入接口
            admin.req({
                url: setter.request.baseUrl + 'user/login',
                data: JSON.stringify({
                    password: MD5(obj.field.password),
                    userName: obj.field.userName
                }),
                type: "post",
                dataType: "json",
                contentType: "application/json",
                done: function(res) {
                    if (res.msg == '操作成功') {
                        console.log(res)
                            //请求成功后，写入 access_token
                        layui.data(setter.tableName, {
                            key: setter.request.tokenName,
                            value: res.code
                        });


                        if (res.info.userName == "admin") {
                            localStorage.setItem('companyName', 0);
                            localStorage.setItem('roleId', 0);
                        } else {
                            localStorage.setItem('companyName', res.info.companyName);
                            localStorage.setItem('roleId', 1);
                        }
                        localStorage.setItem('addTime', res.info.addTime);
                        localStorage.setItem('companyId', res.info.companyId);
                        localStorage.setItem('id', res.info.id);
                        localStorage.setItem('userName', res.info.userName);

                        //登入成功的提示与跳转
                        layer.msg('登录成功', {
                            offset: '15px',
                            icon: 1,
                            time: 1000
                        }, function() {
                            // window.location.href = "/user/user/list"
                            location.hash = search.redirect ? decodeURIComponent(search.redirect) : "/";
                        });
                    }
                    if (res.message == '登录失败') {
                        layer.msg('登录失败', {
                            offset: '15px',
                            icon: 5,
                            time: 1000
                        })
                    }
                }
            });
        });
        $(window).keydown(function(obj) {
            // console.log(obj)
            if (obj.keyCode == 13) {
                admin.req({
                    url: setter.request.baseUrl + 'user/login',
                    data: JSON.stringify({
                        password: MD5($('#LAY-user-login-password').val()),
                        userName: $('#LAY-user-login-username').val()
                    }),
                    type: "post",
                    dataType: "json",
                    contentType: "application/json",
                    done: function(res) {
                        if (res.msg == '操作成功') {
                            console.log(res)
                                //请求成功后，写入 access_token
                            layui.data(setter.tableName, {
                                key: setter.request.tokenName,
                                value: res.code
                            });
                            if (res.info.userName == 'admin') {
                                localStorage.setItem('companyName', 0);
                                localStorage.setItem('roleId', 0);
                            } else {
                                localStorage.setItem('companyName', res.info.companyName);
                                localStorage.setItem('roleId', 1);
                            }
                            localStorage.setItem('addTime', res.info.addTime);
                            localStorage.setItem('companyId', res.info.companyId);
                            localStorage.setItem('id', res.info.id);
                            localStorage.setItem('userName', res.info.userName);
                            //登入成功的提示与跳转
                            layer.msg('登录成功', {
                                offset: '15px',
                                icon: 1,
                                time: 1000
                            }, function() {
                                // console.log("aa")
                                // window.location.href = "/user/user/list"
                                location.hash = search.redirect ? decodeURIComponent(search.redirect) : "/";
                                // console.log("aa")
                            });
                        }
                        if (res.message == '登录失败') {
                            layer.msg('登录失败', {
                                offset: '15px',
                                icon: 5,
                                time: 1000
                            })
                        }
                    }
                });
            }
        });
        //实际使用时记得删除该代码
        layer.msg('请输入账号密码登入后台管理', {
            offset: '15px',
            icon: 1
        });
    });
</script>